package com.projectsexception.festivales.news;

import java.net.URL;

import com.projectsexception.festivales.news.model.Feed;

import android.os.AsyncTask;
import android.util.Log;

public class FeedLoadingTask extends AsyncTask<URL, Void, Feed> {
    
    private FeedTaskActivity feedActivity;
    
    public FeedLoadingTask(FeedTaskActivity feedActivity) {
        super();
        this.feedActivity = feedActivity;
    }
    
    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        Log.i("LoadingTask", "onPreExecute");
        feedActivity.loadingFeed();
    }

    @Override
    protected Feed doInBackground(URL... urls) {
        Log.i("LoadingTask", "doInBackground");
        if (urls.length > 0) {
            URL url = urls[0];
            return SimpleFeedReader.getFeed(url);
        }
        return null;
    }
    
    @Override
    protected void onPostExecute(Feed result) {
        super.onPostExecute(result);
        Log.i("LoadingTask", "onPostExecute");
        feedActivity.feedLoaded(result);
    }

}
